﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;

namespace MapAndCharacter_Filip
{
    public partial class DistanceInfo : Form
    {
        public DistanceInfo()
        {
            InitializeComponent();
            int monCount = 1;
            int charCount = 1;
            foreach (KeyValuePair<int, MovableSprite> entry in GameState.game.characters)
            {
                if (entry.Key >= 100)
                {
                    comboBox1.Items.Add("Monster " + monCount);
                    comboBox2.Items.Add("Monster " + monCount);
                    monCount++;
                }
                else
                {
                    comboBox1.Items.Add("Character " + charCount);
                    comboBox2.Items.Add("Character " + charCount);
                    charCount++;
                }
            }
            comboBox1.Click += new EventHandler(OnBox1Click);
            comboBox2.Click += new EventHandler(OnBox2Click);
        }
        void OnBox1Click(object sender, EventArgs e)
        {
            int monCount = 1;
            int charCount = 1;

            this.comboBox1.Items.Clear();
            foreach (KeyValuePair<int, MovableSprite> entry in GameState.game.characters)
            {
                if (entry.Key >= 100)
                {
                    comboBox1.Items.Add("Monster " + monCount);
                    comboBox2.Items.Add("Monster " + monCount);
                    monCount++;
                }
                else
                {
                    comboBox1.Items.Add("Character " + charCount);
                    comboBox2.Items.Add("Character " + charCount);
                    charCount++;
                }
            }

        }
        void OnBox2Click(object sender, EventArgs e)
        {
            int monCount = 1;
            int charCount = 1;

            this.comboBox2.Items.Clear();
            foreach (KeyValuePair<int, MovableSprite> entry in GameState.game.characters)
            {
                if (entry.Key >= 100)
                {
                    comboBox1.Items.Add("Monster " + monCount);
                    comboBox2.Items.Add("Monster " + monCount);
                    monCount++;
                }
                else
                {
                    comboBox1.Items.Add("Character " + charCount);
                    comboBox2.Items.Add("Character " + charCount);
                    charCount++;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int temp = 0;
            int temp2 = 0;
            if (comboBox1.SelectedItem != null && comboBox2.SelectedItem != null)
            {
                if (comboBox1.Text.Substring(0, 1).Equals("M"))
                {
                    temp = Int32.Parse(comboBox1.Text.Substring(8, comboBox1.Text.Length - 8)) + 100;
                }
                else
                {
                    temp = Int32.Parse(comboBox1.Text.Substring(10, comboBox1.Text.Length - 10));
                }
                if (comboBox2.Text.Substring(0, 1).Equals("M"))
                {
                    temp2 = Int32.Parse(comboBox2.Text.Substring(8, comboBox2.Text.Length - 8)) + 100;
                }
                else
                {
                    temp2 = Int32.Parse(comboBox2.Text.Substring(10, comboBox2.Text.Length - 10));
                }
                double calc = Math.Sqrt(Math.Pow(Math.Abs(GameState.game.characters[temp].Position.X - GameState.game.characters[temp2].Position.X), 2) + Math.Pow(Math.Abs(GameState.game.characters[temp].Position.Y - GameState.game.characters[temp2].Position.Y), 2));
                if ((calc / GameState.scale).ToString().Length < 5)
                {
                    textBox1.Text = (calc / GameState.scale).ToString().Substring(0, (calc / GameState.scale).ToString().Length) + " M";
                }
                else
                {
                    textBox1.Text = (calc / GameState.scale).ToString().Substring(0, 5) + " M";
                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int temp = 0;
            int temp2 = 0;
            if (comboBox2.SelectedItem != null)
            {
                if (comboBox1.Text.Substring(0, 1).Equals("M"))
                {
                    temp = Int32.Parse(comboBox1.Text.Substring(8, comboBox1.Text.Length - 8)) + 100;
                }
                else
                {
                    temp = Int32.Parse(comboBox1.Text.Substring(10, comboBox1.Text.Length - 10));
                }
                if (comboBox2.Text.Substring(0, 1).Equals("M"))
                {
                    temp2 = Int32.Parse(comboBox2.Text.Substring(8, comboBox2.Text.Length - 8)) + 100;
                }
                else
                {
                    temp2 = Int32.Parse(comboBox2.Text.Substring(10, comboBox2.Text.Length - 10));
                }
                double calc = Math.Sqrt(Math.Pow(Math.Abs(GameState.game.characters[temp].Position.X - GameState.game.characters[temp2].Position.X),2) + Math.Pow(Math.Abs(GameState.game.characters[temp].Position.Y - GameState.game.characters[temp2].Position.Y),2));
                if ((calc / GameState.scale).ToString().Length < 5)
                {
                    textBox1.Text = (calc / GameState.scale).ToString().Substring(0, (calc / GameState.scale).ToString().Length) + " M";
                }
                else
                {
                    textBox1.Text = (calc / GameState.scale).ToString().Substring(0, 5) + " M";
                }
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            int temp = 0;
            int temp2 = 0;
            if (comboBox1.SelectedItem != null)
            {
                if (comboBox1.Text.Substring(0, 1).Equals("M"))
                {
                    temp = Int32.Parse(comboBox1.Text.Substring(8, comboBox1.Text.Length - 8)) + 100;
                }
                else
                {
                    temp = Int32.Parse(comboBox1.Text.Substring(10, comboBox1.Text.Length - 10));
                }
                if (comboBox2.Text.Substring(0, 1).Equals("M"))
                {
                    temp2 = Int32.Parse(comboBox2.Text.Substring(8, comboBox2.Text.Length - 8)) + 100;
                }
                else
                {
                    temp2 = Int32.Parse(comboBox2.Text.Substring(10, comboBox2.Text.Length - 10));
                }
                double calc = Math.Sqrt(Math.Pow(Math.Abs(GameState.game.characters[temp].Position.X - GameState.game.characters[temp2].Position.X), 2) + Math.Pow(Math.Abs(GameState.game.characters[temp].Position.Y - GameState.game.characters[temp2].Position.Y), 2));
                if ((calc / GameState.scale).ToString().Length < 5)
                {
                    textBox1.Text = (calc / GameState.scale).ToString().Substring(0, (calc / GameState.scale).ToString().Length) + " M";
                }
                else
                {
                    textBox1.Text = (calc / GameState.scale).ToString().Substring(0, 5) + " M";
                }
            }
        }
    }
}
